/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.scuecsz.view.utils;

import org.scuecsz.utils.*;
import java.util.Map;
import javax.faces.application.Application;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Administrator
 */
public class FaceUtil {

    public  static FacesContext getCurrentInstance(){
        return FacesContext.getCurrentInstance();
    }

    public  static Application getApplication(){
        return getCurrentInstance().getApplication();
    }

    public static ExternalContext getExternalContext() {
        return getCurrentInstance().getExternalContext();
    }

    public static ServletContext getServletContext(){
        return (ServletContext) getExternalContext().getContext();
    }

    public static HttpServletRequest getRequest() {
        return (HttpServletRequest) getExternalContext().getRequest();
    }

    public static Map<String,String> getPageRequestParameterMap() {
        return getExternalContext().getRequestParameterMap();
    }

    public static String getPageRequestParameterValue(String parameterName) {
        return getPageRequestParameterMap().get(parameterName);
    }

    public static HttpServletResponse getResponse() {
        return (HttpServletResponse) getExternalContext().getResponse();
    }

    public static Map getSessionAttributeMap() {
        return getExternalContext().getSessionMap();
    }

    public static void setSessionAttribute(String key,Object value) {
        getExternalContext().getSessionMap().put(key, value);
    }

    public static Object getSessionAttributeValue(String key) {
        return getExternalContext().getSessionMap().get(key);
    }

   public static Object getSessionAttributeValueThenRemove(String key) {
        return getExternalContext().getSessionMap().remove(key);
    }
    
     public static String getFilePath(String path) {
        return getServletContext().getRealPath(path);
    }

    public static String getUsersRoot() {
        return FaceUtil.getFilePath("/datas/user");
    }

    public static String getUserFolder(String userID) {
        return getUsersRoot().concat(FileUtil.subPath(userID));
    }
}
